using System;
using Microsoft.Modeling;

namespace SpecExplorerModel
{
    public class SimpleAsynch
    {
        public static bool Initialized = false;
        public static bool ConnectionOpened = false;
        public static bool QueryOneSent = false;
        public static bool QueryTwoSent = false;
        public static bool QueryThreeSent = false;
        public static bool QueryFourSent = false;
        public static bool QueryFiveSent = false;

        public static bool QueryOneReturned = false;
        public static bool QueryTwoReturned = false;
        public static bool QueryThreeReturned = false;
        public static bool QueryFourReturned = false;
        public static bool QueryFiveReturned = false;

        [Rule]
        public static void Initialize()
        {
            Condition.IsFalse(Initialized);
            Condition.IsFalse(ConnectionOpened);
            Condition.IsFalse(QueryOneSent);
            
            Initialized = true;
        }

        [Rule]
        public static void Connect()
        {
            Condition.IsTrue(Initialized);
            Condition.IsFalse(ConnectionOpened);
            
            ConnectionOpened = true;
        }

        [Rule]
        public static void RunQueryOne()
        {
            Condition.IsTrue(Initialized);
            Condition.IsTrue(ConnectionOpened);
            Condition.IsFalse(QueryOneSent);

            QueryOneSent = true;
        }

        [Rule]
        public static void RunQueryTwo()
        {
            Condition.IsTrue(Initialized);
            Condition.IsTrue(ConnectionOpened);
            Condition.IsFalse(QueryTwoSent);
            QueryTwoSent = true;
        }

        [Rule]
        public static void RunQueryThree()
        {
            Condition.IsTrue(Initialized);
            Condition.IsTrue(ConnectionOpened);
            Condition.IsFalse(QueryThreeSent);
            QueryThreeSent = true;
        }

        [Rule(Action = "Program.QueryOneResponse(resultString)")]
        public static void QueryOneResponse(string resultString)
        {
            Condition.IsTrue(Initialized);
            Condition.IsTrue(ConnectionOpened);
            Condition.IsTrue(QueryOneSent);
            Condition.IsFalse(QueryOneReturned);
            QueryOneReturned = true;
        }

        [Rule(Action = "Program.QueryTwoResponse(resultString)")]
        public static void QueryTwoResponse(string resultString)
        {
            Condition.IsTrue(Initialized);
            Condition.IsTrue(ConnectionOpened);
            Condition.IsTrue(QueryTwoSent);
            Condition.IsFalse(QueryTwoReturned);
            QueryTwoReturned = true;
        }

        [Rule(Action = "Program.QueryThreeResponse(resultString)")]
        public static void QueryThreeResponse(string resultString)
        {
            Condition.IsTrue(Initialized);
            Condition.IsTrue(ConnectionOpened);
            Condition.IsTrue(QueryThreeSent);
            Condition.IsFalse(QueryThreeReturned);
            QueryThreeReturned = true;
        }
    }
}
